# -*- coding: utf-8 -*-
from django.contrib import admin

from acaojudicial.models import AcaoJudicial, GrupoAcao
from acaojudicial.forms import AcaoJudicialForm

#admin.site.register(AcaoJudicial)
#admin.site.register(DetalheAcaoGrupo)
#admin.site.register(GrupoAcao)

class AcaoJudicialAdmin(admin.ModelAdmin):
    form = AcaoJudicialForm
    list_display = ['editar', 'get_data', 'descricao']
    
    def editar(self, obj):
        return '<img src="/media/img/16x16/editar.png" title="Editar" />'
    editar.allow_tags = True
    editar.short_description = ''
    editar.attrs = {'width': '10px'}
    
    def get_data(self, obj):
        return obj.data.strftime("%d de %b. de %Y")
    get_data.short_description = u'Data'
    get_data.admin_order_field = 'data'
    get_data.allow_tags = True
admin.site.register(AcaoJudicial, AcaoJudicialAdmin)

class GrupoAcaoAdmin(admin.ModelAdmin):
    list_display = ['editar', 'get_acao', 'descricao', 'get_servidores']
    
    def editar(self, obj):
        return '<img src="/media/img/16x16/editar.png" title="Editar" />'
    editar.allow_tags = True
    editar.short_description = ''
    editar.attrs = {'width': '10px'}
    
    def get_acao(self, obj):
        return '%s (%s)' % (obj.acao.descricao, obj.acao.data.strftime("%d de %b. de %Y"))
    get_acao.short_description = u'Ação'
    get_acao.admin_order_field = 'acao'
    get_acao.allow_tags = True
    
    def get_servidores(self, obj):
        out = ['<ol>']
        for d in obj.servidor.order_by('nome'):
            out.append('<li>%s</li>' % d.nome)
        out.append('</ol>')
        return ''.join(out)
    get_servidores.short_description = 'Lista de Dependetes'
    get_servidores.admin_order_field = 'servidor'
    get_servidores.allow_tags = True
admin.site.register(GrupoAcao, GrupoAcaoAdmin)